package org.liu.knowledge.chatMemory;

import dev.langchain4j.data.message.SystemMessage;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.chat.response.ChatResponse;
import dev.langchain4j.model.ollama.OllamaChatModel;

public class MemoryExample {
    static OllamaChatModel model = OllamaChatModel.builder()
            .baseUrl("http://localhost:11434/")
            .modelName("qwen2.5:3b")
            .build();

    public static void main(String[] args) {
        MessageWindowChatMemory memory = MessageWindowChatMemory.builder()
                .maxMessages(10)
                .build();

        UserMessage msg = UserMessage.from("你好啊,我叫刘");
        memory.add(msg);
        ChatResponse chat = model.chat(memory.messages());
        System.out.println(chat.aiMessage().text());

        memory.add(chat.aiMessage());
        memory.add(UserMessage.from("我叫什么"));

        chat = model.chat(memory.messages());
        System.out.println(chat.aiMessage().text());
    }
}
